<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
    String contextPath = request.getContextPath();
    request.setAttribute("contextPath", contextPath);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title>图书</title>
	<%-- <%
	Page pageList=new Page();
	request.setAttribute("pages",pageList);
	%>
	<script> 
	function _gotoPage(pageNo) {  
		try{
			pages.pageNo=pageNo;
			pages.prePage=pageNo-1;
			pages.nextPage=pageNo+1;   
			List<Book> list=request.getAttribution("list");
			List<Book> books=list.subList((pageNo-1)*3,pageNo*3);
			request.setAttribution("books",books);
	 } catch(e) { 
	  	alert('gotoPage(pageNo)方法出错或不存在');  } 
	} 
	</script> --%>

</head>
<body>
<c:if test="${not empty LOGIN_USER_KEY_IN_SESSION }">
<b>${LOGIN_USER_KEY_IN_SESSION.userName }</b>欢迎你!
	<h2><a href="${contextPath }/logout"/>logout</a></h2>
	<c:if test="${userRole.roleName!='普通用户' }">
			<input type="button" name="manage" value="manage" onclick="location=('${contextPath }/admin')"/>
	</c:if>
</c:if>
<c:if test="${empty LOGIN_USER_KEY_IN_SESSION }">
	<h2><a href="${contextPath }/gotoLogin"/>login</a></h2>
</c:if>
	<h1>
	<tr>
		<a href="${contextPath }/showallbooks">全部书籍</a>
	</tr>
	<tr>
		<a href="${contextPath }/showBookSpecials">特价书籍</a>
	</tr>
	<br />
	</h1>
	<%--列表过滤栏 --%>
	<c:forEach items="${category }" var="cate">
		<tr>
			<a href="${contextPath }/filter/${cate.categoryId}">${cate.categoryName }</a>
		</tr>
		<br />
	</c:forEach>
	
	<%-- <form>
	<input type="button" value="首 页" onclick="_gotoPage('1');"/>&nbsp;	  
	<input type="button" value="上一页" onclick="_gotoPage('${pages.prePage}');"/>&nbsp;
	<input type="button" value="下一页" onclick="_gotoPage('${pages.nextPage}');"/>&nbsp;
	当前 ${pages.pageNo}/${pages.totalPage} 页 &nbsp;
	转到第<input  type="text"  id="_goPs"  size="2"  onfocus="this.select();" onKeyUp="value=value.replace(/[^\d\.]/g,'')" onkeypress="if(event.keyCode==13){$('#_goPage').click();return false;}" /> 页	  
	<input id="_goPage" type="button" value="转" onclick="_gotoPage($('#_goPs').val());"  /> 
	</form> --%>
	<table width="80%" border="1" name="bookTable" id="bookTable">
		<tr style="color:red">
			<td>bookId</td>
			<td>categoryId</td>
			<td>bookName</td>
			<td>bookAuthor</td>
			<td>ISBN</td>
			<td>bookPub</td>
			<td>bookDescription</td>
			<td>stockNumber</td>
			<td>bookImg</td>
			<td>raterNumber</td>
			<td>averageNumber</td>
			<td>isAvailable</td>
			<td>操作</td>
		</tr>
		<c:forEach items="${list }" var="book">
			<tr>
				<td>${book.bookId }</td>
				<td>${book.categoryId }</td>
				<td>${book.bookName }</td>
				<td>${book.bookAuthor }</td>
				<td>${book.ISBN }</td>
				<td>${book.bookPub }</td>
				<td>${book.bookDescription }</td>
				<td>${book.stockNumber }</td>
				<td>${book.bookImg }</td>
				<td>${book.raterNumber }</td>
				<td>${book.averageNumber }</td>
				<td>${book.isAvailable }</td>
				<td><a href="${contextPath }/book1/${book.bookId}">查看图书</a></td>
			</tr>
		</c:forEach>
	</table>
	<br />
	<!-- 搜索栏 -->
	<form action="${contextPath }/search">
		<input type="text" name="bookName" id="bookName" /> 
		<select	name="categoryId">
			<!-- select有默认，如若不指定，则默认以第一个为默认 -->
			<option value="0">全部书籍</option>
			<option value="1">儿童读物</option>
			<option value="2">科幻读物</option>
			<option value="3">冒险读物</option>
			<option value="4">悬疑读物</option>
			<option value="5">推理读物</option>
			<option value="6">科幻读物</option>
			<option value="6">恐怖读物</option>
		</select> <input type="submit" value="search" />
	</form>
	<br />------------------------- 查找结果：
	<br />
	<c:if test="${empty search }">
		<b>无相关搜索记录</b>
	</c:if>
	<table width="80%" border="1">
		<c:if test="${not empty search }">
			<c:forEach items="${search }" var="book">
				<tr>
					<td>${book.bookId }</td>
					<td>${book.categoryId }</td>
					<td>${book.bookName }</td>
					<td>${book.bookAuthor }</td>
					<td>${book.ISBN }</td>
					<td>${book.bookPub }</td>
					<td>${book.bookDescription }</td>
					<td>${book.stockNumber }</td>
					<td>${book.bookImg }</td>
					<td>${book.raterNumber }</td>
					<td>${book.averageNumber }</td>
					<td>${book.isAvailable }</td>
					<td><a href="${contextPath }/book/${book.bookId}">查看图书</a></td>
				</tr>
			</c:forEach>
		</c:if>
	</table>
</body>
</html>